home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / info / internals.info-1.z / internals.info-1
Encoding:
GNU Info File  |  1998-05-21  |  42.0 KB  |  1,013 lines

  1. This is Info file ../../info/internals.info, produced by Makeinfo
  2. version 1.68 from the input file internals.texi.
  3.  
  4.    Copyright (C) 1992 - 1996 Ben Wing.  Copyright (C) 1996, 1997 Sun
  5. Microsystems.  Copyright (C) 1994, 1995 Free Software Foundation.
  6. Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.  
  17.    Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions, except that this permission notice may be stated in a
  20. translation approved by the Foundation.
  21.  
  22.    Permission is granted to copy and distribute modified versions of
  23. this manual under the conditions for verbatim copying, provided also
  24. that the section entitled "GNU General Public License" is included
  25. exactly as in the original, and provided that the entire resulting
  26. derived work is distributed under the terms of a permission notice
  27. identical to this one.
  28.  
  29.    Permission is granted to copy and distribute translations of this
  30. manual into another language, under the above conditions for modified
  31. versions, except that the section entitled "GNU General Public License"
  32. may be included in a translation approved by the Free Software
  33. Foundation instead of in the original English.
  34.  
  35. 
  36. File: internals.info,  Node: Top,  Next: A History of Emacs,  Prev: (dir),  Up: (dir)
  37.  
  38.    This Info file contains v1.0 of the XEmacs Internals Manual.
  39.  
  40. * Menu:
  41.  
  42. * A History of Emacs::          Times, dates, important events.
  43. * XEmacs From the Outside::     A broad conceptual overview.
  44. * The Lisp Language::           An overview.
  45. * XEmacs From the Perspective of Building::
  46. * XEmacs From the Inside::
  47. * The XEmacs Object System (Abstractly Speaking)::
  48. * How Lisp Objects Are Represented in C::
  49. * Rules When Writing New C Code::
  50. * A Summary of the Various XEmacs Modules::
  51. * Allocation of Objects in XEmacs Lisp::
  52. * Events and the Event Loop::
  53. * Evaluation; Stack Frames; Bindings::
  54. * Symbols and Variables::
  55. * Buffers and Textual Representation::
  56. * MULE Character Sets and Encodings::
  57. * The Lisp Reader and Compiler::
  58. * Lstreams::
  59. * Consoles; Devices; Frames; Windows::
  60. * The Redisplay Mechanism::
  61. * Extents::
  62. * Faces and Glyphs::
  63. * Specifiers::
  64. * Menus::
  65. * Subprocesses::
  66. * Interface to X Windows::
  67. * Index::                   Index including concepts, functions, variables,
  68.                               and other terms.
  69.  
  70.       -- The Detailed Node Listing --
  71.  
  72. Here are other nodes that are inferiors of those already listed,
  73. mentioned here so you can get to them in one step:
  74.  
  75. A History of Emacs
  76.  
  77. * Through Version 18::          Unification prevails.
  78. * Lucid Emacs::                 One version 19 Emacs.
  79. * GNU Emacs 19::                The other version 19 Emacs.
  80. * XEmacs::                      The continuation of Lucid Emacs.
  81.  
  82. Rules When Writing New C Code
  83.  
  84. * General Coding Rules::
  85. * Writing Lisp Primitives::
  86. * Adding Global Lisp Variables::
  87. * Techniques for XEmacs Developers::
  88.  
  89. A Summary of the Various XEmacs Modules
  90.  
  91. * Low-Level Modules::
  92. * Basic Lisp Modules::
  93. * Modules for Standard Editing Operations::
  94. * Editor-Level Control Flow Modules::
  95. * Modules for the Basic Displayable Lisp Objects::
  96. * Modules for other Display-Related Lisp Objects::
  97. * Modules for the Redisplay Mechanism::
  98. * Modules for Interfacing with the File System::
  99. * Modules for Other Aspects of the Lisp Interpreter and Object System::
  100. * Modules for Interfacing with the Operating System::
  101. * Modules for Interfacing with X Windows::
  102. * Modules for Internationalization::
  103.  
  104. Allocation of Objects in XEmacs Lisp
  105.  
  106. * Introduction to Allocation::
  107. * Garbage Collection::
  108. * GCPROing::
  109. * Integers and Characters::
  110. * Allocation from Frob Blocks::
  111. * lrecords::
  112. * Low-level allocation::
  113. * Pure Space::
  114. * Cons::
  115. * Vector::
  116. * Bit Vector::
  117. * Symbol::
  118. * Marker::
  119. * String::
  120. * Bytecode::
  121.  
  122. Events and the Event Loop
  123.  
  124. * Introduction to Events::
  125. * Main Loop::
  126. * Specifics of the Event Gathering Mechanism::
  127. * Specifics About the Emacs Event::
  128. * The Event Stream Callback Routines::
  129. * Other Event Loop Functions::
  130. * Converting Events::
  131. * Dispatching Events; The Command Builder::
  132.  
  133. Evaluation; Stack Frames; Bindings
  134.  
  135. * Evaluation::
  136. * Dynamic Binding; The specbinding Stack; Unwind-Protects::
  137. * Simple Special Forms::
  138. * Catch and Throw::
  139.  
  140. Symbols and Variables
  141.  
  142. * Introduction to Symbols::
  143. * Obarrays::
  144. * Symbol Values::
  145.  
  146. Buffers and Textual Representation
  147.  
  148. * Introduction to Buffers::     A buffer holds a block of text such as a file.
  149. * The Text in a Buffer::        Representation of the text in a buffer.
  150. * Buffer Lists::                Keeping track of all buffers.
  151. * Markers and Extents::         Tagging locations within a buffer.
  152. * Bufbytes and Emchars::        Representation of individual characters.
  153. * The Buffer Object::           The Lisp object corresponding to a buffer.
  154.  
  155. MULE Character Sets and Encodings
  156.  
  157. * Character Sets::
  158. * Encodings::
  159. * Internal Mule Encodings::
  160.  
  161. Encodings
  162.  
  163. * Japanese EUC (Extended Unix Code)::
  164. * JIS7::
  165.  
  166. Internal Mule Encodings
  167.  
  168. * Internal String Encoding::
  169. * Internal Character Encoding::
  170.  
  171. The Lisp Reader and Compiler
  172.  
  173. Lstreams
  174.  
  175. Consoles; Devices; Frames; Windows
  176.  
  177. * Introduction to Consoles; Devices; Frames; Windows::
  178. * Point::
  179. * Window Hierarchy::
  180.  
  181. The Redisplay Mechanism
  182.  
  183. * Critical Redisplay Sections::
  184. * Line Start Cache::
  185.  
  186. Extents
  187.  
  188. * Introduction to Extents::     Extents are ranges over text, with properties.
  189. * Extent Ordering::             How extents are ordered internally.
  190. * Format of the Extent Info::   The extent information in a buffer or string.
  191. * Zero-Length Extents::         A weird special case.
  192. * Mathematics of Extent Ordering::      A rigorous foundation.
  193. * Extent Fragments::            Cached information useful for redisplay.
  194.  
  195. Faces and Glyphs
  196.  
  197. Specifiers
  198.  
  199. Menus
  200.  
  201. Subprocesses
  202.  
  203. Interface to X Windows
  204.  
  205. 
  206. File: internals.info,  Node: A History of Emacs,  Next: XEmacs From the Outside,  Prev: Top,  Up: Top
  207.  
  208. A History of Emacs
  209. ******************
  210.  
  211.    XEmacs is a powerful, customizable text editor and development
  212. environment.  It began as Lucid Emacs, which was in turn derived from
  213. GNU Emacs, a program written by Richard Stallman of the Free Software
  214. Foundation.  GNU Emacs dates back to the 1970's, and was modelled after
  215. a package called "Emacs", written in 1976, that was a set of macros on
  216. top of TECO, an old, old text editor written at MIT on the DEC PDP 10
  217. under one of the earliest time-sharing operating systems, ITS
  218. (Incompatible Timesharing System). (ITS dates back well before Unix.)
  219. ITS, TECO, and Emacs were products of a group of people at MIT who
  220. called themselves "hackers", who shared an idealistic belief system
  221. about the free exchange of information and were fanatical in their
  222. devotion to and time spent with computers. (The hacker subculture dates
  223. back to the late 1950's at MIT and is described in detail in Steven
  224. Levy's book `Hackers'.  This book also includes a lot of information
  225. about Stallman himself and the development of Lisp, a programming
  226. language developed at MIT that underlies Emacs.)
  227.  
  228. * Menu:
  229.  
  230. * Through Version 18::          Unification prevails.
  231. * Lucid Emacs::                 One version 19 Emacs.
  232. * GNU Emacs 19::                The other version 19 Emacs.
  233. * GNU Emacs 20::                The other version 20 Emacs.
  234. * XEmacs::                      The continuation of Lucid Emacs.
  235.  
  236. 
  237. File: internals.info,  Node: Through Version 18,  Next: Lucid Emacs,  Up: A History of Emacs
  238.  
  239. Through Version 18
  240. ==================
  241.  
  242.    Although the history of the early versions of GNU Emacs is unclear,
  243. the history is well-known from the middle of 1985.  A time line is:
  244.  
  245.    * GNU Emacs version 15 (15.34) was released sometime in 1984 or 1985
  246.      and shared some code with a version of Emacs written by James
  247.      Gosling (the same James Gosling who later created the Java
  248.      language).
  249.  
  250.    * GNU Emacs version 16 (first released version was 16.56) was
  251.      released on July 15, 1985.  All Gosling code was removed due to
  252.      potential copyright problems with the code.
  253.  
  254.    * version 16.57: released on September 16, 1985.
  255.  
  256.    * versions 16.58, 16.59: released on September 17, 1985.
  257.  
  258.    * version 16.60: released on September 19, 1985.  These later
  259.      version 16's incorporated patches from the net, esp. for getting
  260.      Emacs to work under System V.
  261.  
  262.    * version 17.36 (first official v17 release) released on December 20,
  263.      1985.  Included a TeX-able user manual.  First official unpatched
  264.      version that worked on vanilla System V machines.
  265.  
  266.    * version 17.43 (second official v17 release) released on January 25,
  267.      1986.
  268.  
  269.    * version 17.45 released on January 30, 1986.
  270.  
  271.    * version 17.46 released on February 4, 1986.
  272.  
  273.    * version 17.48 released on February 10, 1986.
  274.  
  275.    * version 17.49 released on February 12, 1986.
  276.  
  277.    * version 17.55 released on March 18, 1986.
  278.  
  279.    * version 17.57 released on March 27, 1986.
  280.  
  281.    * version 17.58 released on April 4, 1986.
  282.  
  283.    * version 17.61 released on April 12, 1986.
  284.  
  285.    * version 17.63 released on May 7, 1986.
  286.  
  287.    * version 17.64 released on May 12, 1986.
  288.  
  289.    * version 18.24 (a beta version) released on October 2, 1986.
  290.  
  291.    * version 18.30 (a beta version) released on November 15, 1986.
  292.  
  293.    * version 18.31 (a beta version) released on November 23, 1986.
  294.  
  295.    * version 18.32 (a beta version) released on December 7, 1986.
  296.  
  297.    * version 18.33 (a beta version) released on December 12, 1986.
  298.  
  299.    * version 18.35 (a beta version) released on January 5, 1987.
  300.  
  301.    * version 18.36 (a beta version) released on January 21, 1987.
  302.  
  303.    * January 27, 1987: The Great Usenet Renaming.  net.emacs is now
  304.      comp.emacs.
  305.  
  306.    * version 18.37 (a beta version) released on February 12, 1987.
  307.  
  308.    * version 18.38 (a beta version) released on March 3, 1987.
  309.  
  310.    * version 18.39 (a beta version) released on March 14, 1987.
  311.  
  312.    * version 18.40 (a beta version) released on March 18, 1987.
  313.  
  314.    * version 18.41 (the first "official" release) released on March 22,
  315.      1987.
  316.  
  317.    * version 18.45 released on June 2, 1987.
  318.  
  319.    * version 18.46 released on June 9, 1987.
  320.  
  321.    * version 18.47 released on June 18, 1987.
  322.  
  323.    * version 18.48 released on September 3, 1987.
  324.  
  325.    * version 18.49 released on September 18, 1987.
  326.  
  327.    * version 18.50 released on February 13, 1988.
  328.  
  329.    * version 18.51 released on May 7, 1988.
  330.  
  331.    * version 18.52 released on September 1, 1988.
  332.  
  333.    * version 18.53 released on February 24, 1989.
  334.  
  335.    * version 18.54 released on April 26, 1989.
  336.  
  337.    * version 18.55 released on August 23, 1989.  This is the earliest
  338.      version that is still available by FTP.
  339.  
  340.    * version 18.56 released on January 17, 1991.
  341.  
  342.    * version 18.57 released late January, 1991.
  343.  
  344.    * version 18.58 released ?????.
  345.  
  346.    * version 18.59 released October 31, 1992.
  347.  
  348. 
  349. File: internals.info,  Node: Lucid Emacs,  Next: GNU Emacs 19,  Prev: Through Version 18,  Up: A History of Emacs
  350.  
  351. Lucid Emacs
  352. ===========
  353.  
  354.    Lucid Emacs was developed by the (now-defunct) Lucid Inc., a maker of
  355. C++ and Lisp development environments.  It began when Lucid decided they
  356. wanted to use Emacs as the editor and cornerstone of their C++
  357. development environment (called "Energize").  They needed many features
  358. that were not available in the existing version of GNU Emacs (version
  359. 18.5something), in particular good and integrated support for GUI
  360. elements such as mouse support, multiple fonts, multiple window-system
  361. windows, etc.  A branch of GNU Emacs called Epoch, written at the
  362. University of Illinois, existed that supplied many of these features;
  363. however, Lucid needed more than what existed in Epoch.  At the time, the
  364. Free Software Foundation was working on version 19 of Emacs (this was
  365. sometime around 1991), which was planned to have similar features, and
  366. so Lucid decided to work with the Free Software Foundation.  Their plan
  367. was to add features that they needed, and coordinate with the FSF so
  368. that the features would get included back into Emacs version 19.
  369.  
  370.    Delays in the release of version 19 occurred, however (resulting in
  371. it finally being released more than a year after what was initially
  372. planned), and Lucid encountered unexpected technical resistance in
  373. getting their changes merged back into version 19, so they decided to
  374. release their own version of Emacs, which became Lucid Emacs 19.0.
  375.  
  376.    The initial authors of Lucid Emacs were Matthieu Devin, Harlan
  377. Sexton, and Eric Benson, and the work was later taken over by Jamie
  378. Zawinski, who became "Mr. Lucid Emacs" for many releases.
  379.  
  380.    A time line for Lucid Emacs/XEmacs is
  381.  
  382.    * version 19.0 shipped with Energize 1.0, April 1992.
  383.  
  384.    * version 19.1 released June 4, 1992.
  385.  
  386.    * version 19.2 released June 19, 1992.
  387.  
  388.    * version 19.3 released September 9, 1992.
  389.  
  390.    * version 19.4 released January 21, 1993.
  391.  
  392.    * version 19.5 was a repackaging of 19.4 with a few bug fixes and
  393.      shipped with Energize 2.0.  Never released to the net.
  394.  
  395.    * version 19.6 released April 9, 1993.
  396.  
  397.    * version 19.7 was a repackaging of 19.6 with a few bug fixes and
  398.      shipped with Energize 2.1.  Never released to the net.
  399.  
  400.    * version 19.8 released September 6, 1993.
  401.  
  402.    * version 19.9 released January 12, 1994.
  403.  
  404.    * version 19.10 released May 27, 1994.
  405.  
  406.    * version 19.11 (first XEmacs) released September 13, 1994.
  407.  
  408.    * version 19.12 released June 23, 1995.
  409.  
  410.    * version 19.13 released September 1, 1995.
  411.  
  412.    * version 19.14 released June 23, 1996.
  413.  
  414.    * version 20.0 released February 9, 1997.
  415.  
  416.    * version 19.15 released March 28, 1997.
  417.  
  418.    * version 20.1 (not released to the net) April 15, 1997.
  419.  
  420.    * version 20.2 released May 16, 1997.
  421.  
  422.    * version 19.16 released October 31, 1997.
  423.  
  424. 
  425. File: internals.info,  Node: GNU Emacs 19,  Next: GNU Emacs 20,  Prev: Lucid Emacs,  Up: A History of Emacs
  426.  
  427. GNU Emacs 19
  428. ============
  429.  
  430.    About a year after the initial release of Lucid Emacs, the FSF
  431. released a beta of their version of Emacs 19 (referred to here as "GNU
  432. Emacs").  By this time, the current version of Lucid Emacs was 19.6.
  433. (Strangely, the first released beta from the FSF was GNU Emacs 19.7.) A
  434. time line for GNU Emacs version 19 is
  435.  
  436.    * version 19.8 (beta) released May 27, 1993.
  437.  
  438.    * version 19.9 (beta) released May 27, 1993.
  439.  
  440.    * version 19.10 (beta) released May 30, 1993.
  441.  
  442.    * version 19.11 (beta) released June 1, 1993.
  443.  
  444.    * version 19.12 (beta) released June 2, 1993.
  445.  
  446.    * version 19.13 (beta) released June 8, 1993.
  447.  
  448.    * version 19.14 (beta) released June 17, 1993.
  449.  
  450.    * version 19.15 (beta) released June 19, 1993.
  451.  
  452.    * version 19.16 (beta) released July 6, 1993.
  453.  
  454.    * version 19.17 (beta) released late July, 1993.
  455.  
  456.    * version 19.18 (beta) released August 9, 1993.
  457.  
  458.    * version 19.19 (beta) released August 15, 1993.
  459.  
  460.    * version 19.20 (beta) released November 17, 1993.
  461.  
  462.    * version 19.21 (beta) released November 17, 1993.
  463.  
  464.    * version 19.22 (beta) released November 28, 1993.
  465.  
  466.    * version 19.23 (beta) released May 17, 1994.
  467.  
  468.    * version 19.24 (beta) released May 16, 1994.
  469.  
  470.    * version 19.25 (beta) released June 3, 1994.
  471.  
  472.    * version 19.26 (beta) released September 11, 1994.
  473.  
  474.    * version 19.27 (beta) released September 14, 1994.
  475.  
  476.    * version 19.28 (first "official" release) released November 1, 1994.
  477.  
  478.    * version 19.29 released June 21, 1995.
  479.  
  480.    * version 19.30 released November 24, 1995.
  481.  
  482.    * version 19.31 released May 25, 1996.
  483.  
  484.    * version 19.32 released July 31, 1996.
  485.  
  486.    * version 19.33 released August 11, 1996.
  487.  
  488.    * version 19.34 released August 21, 1996.
  489.  
  490.    * version 19.34b released September 6, 1996.
  491.  
  492.    In some ways, GNU Emacs 19 was better than Lucid Emacs; in some ways,
  493. worse.  Lucid soon began incorporating features from GNU Emacs 19 into
  494. Lucid Emacs; the work was mostly done by Richard Mlynarik, who had been
  495. working on and using GNU Emacs for a long time (back as far as version
  496. 16 or 17).
  497.  
  498. 
  499. File: internals.info,  Node: GNU Emacs 20,  Next: XEmacs,  Prev: GNU Emacs 19,  Up: A History of Emacs
  500.  
  501. GNU Emacs 20
  502. ============
  503.  
  504.    On February 2, 1997 work began on GNU Emacs to integrate Mule.  The
  505. first release was made in September of that year.
  506.  
  507.    A timeline for Emacs 20 is
  508.  
  509.    * version 20.1 released September 17, 1997.
  510.  
  511.    * version 20.2 released September 20, 1997.
  512.  
  513. 
  514. File: internals.info,  Node: XEmacs,  Prev: GNU Emacs 20,  Up: A History of Emacs
  515.  
  516. XEmacs
  517. ======
  518.  
  519.    Around the time that Lucid was developing Energize, Sun Microsystems
  520. was developing their own development environment (called "SPARCWorks")
  521. and also decided to use Emacs.  They joined forces with the Epoch team
  522. at the University of Illinois and later with Lucid.  The maintainer of
  523. the last-released version of Epoch was Marc Andreessen, but he dropped
  524. out and the Epoch project, headed by Simon Kaplan, lured Chuck Thompson
  525. away from a system administration job to become the primary Lucid Emacs
  526. author for Epoch and Sun.  Chuck's area of specialty became the
  527. redisplay engine (he replaced the old Lucid Emacs redisplay engine with
  528. a ported version from Epoch and then later rewrote it from scratch).
  529. Sun also hired Ben Wing (the author of Win-Emacs, a port of Lucid Emacs
  530. to Microsoft Windows 3.1) in 1993, for what was initially a one-month
  531. contract to fix some event problems but later became a many-year
  532. involvement, punctuated by a six-month contract with Amdahl Corporation.
  533.  
  534.    In 1994, Sun and Lucid agreed to rename Lucid Emacs to XEmacs (a name
  535. not favorable to either company); the first release called XEmacs was
  536. version 19.11.  In June 1994, Lucid folded and Jamie quit to work for
  537. the newly formed Mosaic Communications Corp., later Netscape
  538. Communications Corp. (co-founded by the same Marc Andreessen, who had
  539. quit his Epoch job to work on a graphical browser for the World Wide
  540. Web).  Chuck then become the primary maintainer of XEmacs, and put out
  541. versions 19.11 through 19.14 in conjunction with Ben.  For 19.12 and
  542. 19.13, Chuck added the new redisplay and many other display improvements
  543. and Ben added MULE support (support for Asian and other languages) and
  544. redesigned most of the internal Lisp subsystems to better support the
  545. MULE work and the various other features being added to XEmacs.  After
  546. 19.14 Chuck retired as primary maintainer and Steve Baur stepped in.
  547.  
  548.    Soon after 19.13 was released, work began in earnest on the MULE
  549. internationalization code and the source tree was divided into two
  550. development paths.  The MULE version was initially called 19.20, but was
  551. soon renamed to 20.0.  In 1996 Martin Buchholz of Sun Microsystems took
  552. over the care and feeding of it and worked on it in parallel with the
  553. 19.14 development that was occurring at the same time.  After much work
  554. by Martin, it was decided to release 20.0 ahead of 19.15 in February
  555. 1997.  The source tree remained divided until 20.1 when the version 19
  556. source was finally retired.
  557.  
  558.    Many attempts have been made to merge XEmacs and GNU Emacs, but they
  559. have consistently run into the same technical disagreements and other
  560. problems that Lucid ran into when originally attempting to merge Lucid
  561. Emacs into GNU Emacs.
  562.  
  563.    A more detailed history is contained in the XEmacs About page.
  564.  
  565. 
  566. File: internals.info,  Node: XEmacs From the Outside,  Next: The Lisp Language,  Prev: A History of Emacs,  Up: Top
  567.  
  568. XEmacs From the Outside
  569. ***********************
  570.  
  571.    XEmacs appears to the outside world as an editor, but it is really a
  572. Lisp environment.  At its heart is a Lisp interpreter; it also
  573. "happens" to contain many specialized object types (e.g. buffers,
  574. windows, frames, events) that are useful for implementing an editor.
  575. Some of these objects (in particular windows and frames) have
  576. displayable representations, and XEmacs provides a function
  577. `redisplay()' that ensures that the display of all such objects matches
  578. their internal state.  Most of the time, a standard Lisp environment is
  579. in a "read-eval-print" loop - i.e. "read some Lisp code, execute it,
  580. and print the results".  XEmacs has a similar loop:
  581.  
  582.    * read an event
  583.  
  584.    * dispatch the event (i.e. "do it")
  585.  
  586.    * redisplay
  587.  
  588.    Reading an event is done using the Lisp function `next-event', which
  589. waits for something to happen (typically, the user presses a key or
  590. moves the mouse) and returns an event object describing this.
  591. Dispatching an event is done using the Lisp function `dispatch-event',
  592. which looks up the event in a keymap object (a particular kind of
  593. object that associates an event with a Lisp function) and calls that
  594. function.  The function "does" what the user has requested by changing
  595. the state of particular frame objects, buffer objects, etc.  Finally,
  596. `redisplay()' is called, which updates the display to reflect those
  597. changes just made.  Thus is an "editor" born.
  598.  
  599.    Note that you do not have to use XEmacs as an editor; you could just
  600. as well make it do your taxes, compute pi, play bridge, etc.  You'd just
  601. have to write functions to do those operations in Lisp.
  602.  
  603. 
  604. File: internals.info,  Node: The Lisp Language,  Next: XEmacs From the Perspective of Building,  Prev: XEmacs From the Outside,  Up: Top
  605.  
  606. The Lisp Language
  607. *****************
  608.  
  609.    Lisp is a general-purpose language that is higher-level than C and in
  610. many ways more powerful than C.  Powerful dialects of Lisp such as
  611. Common Lisp are probably much better languages for writing very large
  612. applications than is C. (Unfortunately, for many non-technical reasons
  613. C and its successor C++ have become the dominant languages for
  614. application development.  These languages are both inadequate for
  615. extremely large applications, which is evidenced by the fact that newer,
  616. larger programs are becoming ever harder to write and are requiring ever
  617. more programmers despite great increases in C development environments;
  618. and by the fact that, although hardware speeds and reliability have been
  619. growing at an exponential rate, most software is still generally
  620. considered to be slow and buggy.)
  621.  
  622.    The new Java language holds promise as a better general-purpose
  623. development language than C.  Java has many features in common with
  624. Lisp that are not shared by C (this is not a coincidence, since Java
  625. was designed by James Gosling, a former Lisp hacker).  This will be
  626. discussed more later.
  627.  
  628.    For those used to C, here is a summary of the basic differences
  629. between C and Lisp:
  630.  
  631.   1. Lisp has an extremely regular syntax.  Every function, expression,
  632.      and control statement is written in the form
  633.  
  634.              (FUNC ARG1 ARG2 ...)
  635.  
  636.      This is as opposed to C, which writes functions as
  637.  
  638.              func(ARG1, ARG2, ...)
  639.  
  640.      but writes expressions involving operators as (e.g.)
  641.  
  642.              ARG1 + ARG2
  643.  
  644.      and writes control statements as (e.g.)
  645.  
  646.              while (EXPR) { STATEMENT1; STATEMENT2; ... }
  647.  
  648.      Lisp equivalents of the latter two would be
  649.  
  650.              (+ ARG1 ARG2 ...)
  651.  
  652.      and
  653.  
  654.              (while EXPR STATEMENT1 STATEMENT2 ...)
  655.  
  656.   2. Lisp is a safe language.  Assuming there are no bugs in the Lisp
  657.      interpreter/compiler, it is impossible to write a program that
  658.      "core dumps" or otherwise causes the machine to execute an illegal
  659.      instruction.  This is very different from C, where perhaps the most
  660.      common outcome of a bug is exactly such a crash.  A corollary of
  661.      this is that the C operation of casting a pointer is impossible
  662.      (and unnecessary) in Lisp, and that it is impossible to access
  663.      memory outside the bounds of an array.
  664.  
  665.   3. Programs and data are written in the same form.  The
  666.      parenthesis-enclosing form described above for statements is the
  667.      same form used for the most common data type in Lisp, the list.
  668.      Thus, it is possible to represent any Lisp program using Lisp data
  669.      types, and for one program to construct Lisp statements and then
  670.      dynamically "evaluate" them, or cause them to execute.
  671.  
  672.   4. All objects are "dynamically typed".  This means that part of every
  673.      object is an indication of what type it is.  A Lisp program can
  674.      manipulate an object without knowing what type it is, and can
  675.      query an object to determine its type.  This means that,
  676.      correspondingly, variables and function parameters can hold
  677.      objects of any type and are not normally declared as being of any
  678.      particular type.  This is opposed to the "static typing" of C,
  679.      where variables can hold exactly one type of object and must be
  680.      declared as such, and objects do not contain an indication of
  681.      their type because it's implicit in the variables they are stored
  682.      in.  It is possible in C to have a variable hold different types
  683.      of objects (e.g. through the use of `void *' pointers or
  684.      variable-argument functions), but the type information must then be
  685.      passed explicitly in some other fashion, leading to additional
  686.      program complexity.
  687.  
  688.   5. Allocated memory is automatically reclaimed when it is no longer
  689.      in use.  This operation is called "garbage collection" and
  690.      involves looking through all variables to see what memory is being
  691.      pointed to, and reclaiming any memory that is not pointed to and
  692.      is thus "inaccessible" and out of use.  This is as opposed to C,
  693.      in which allocated memory must be explicitly reclaimed using
  694.      `free()'.  If you simply drop all pointers to memory without
  695.      freeing it, it becomes "leaked" memory that still takes up space.
  696.      Over a long period of time, this can cause your program to grow
  697.      and grow until it runs out of memory.
  698.  
  699.   6. Lisp has built-in facilities for handling errors and exceptions.
  700.      In C, when an error occurs, usually either the program exits
  701.      entirely or the routine in which the error occurs returns a value
  702.      indicating this.  If an error occurs in a deeply-nested routine,
  703.      then every routine currently called must unwind itself normally
  704.      and return an error value back up to the next routine.  This means
  705.      that every routine must explicitly check for an error in all the
  706.      routines it calls; if it does not do so, unexpected and often
  707.      random behavior results.  This is an extremely common source of
  708.      bugs in C programs.  An alternative would be to do a non-local
  709.      exit using `longjmp()', but that is often very dangerous because
  710.      the routines that were exited past had no opportunity to clean up
  711.      after themselves and may leave things in an inconsistent state,
  712.      causing a crash shortly afterwards.
  713.  
  714.      Lisp provides mechanisms to make such non-local exits safe.  When
  715.      an error occurs, a routine simply signals that an error of a
  716.      particular class has occurred, and a non-local exit takes place.
  717.      Any routine can trap errors occurring in routines it calls by
  718.      registering an error handler for some or all classes of errors.
  719.      (If no handler is registered, a default handler, generally
  720.      installed by the top-level event loop, is executed; this prints
  721.      out the error and continues.) Routines can also specify cleanup
  722.      code (called an "unwind-protect") that will be called when control
  723.      exits from a block of code, no matter how that exit occurs - i.e.
  724.      even if a function deeply nested below it causes a non-local exit
  725.      back to the top level.
  726.  
  727.      Note that this facility has appeared in some recent vintages of C,
  728.      in particular Visual C++ and other PC compilers written for the
  729.      Microsoft Win32 API.
  730.  
  731.   7. In Emacs Lisp, local variables are "dynamically scoped".  This
  732.      means that if you declare a local variable in a particular
  733.      function, and then call another function, that subfunction can
  734.      "see" the local variable you declared.  This is actually
  735.      considered a bug in Emacs Lisp and in all other early dialects of
  736.      Lisp, and was corrected in Common Lisp. (In Common Lisp, you can
  737.      still declare dynamically scoped variables if you want to - they
  738.      are sometimes useful - but variables by default are "lexically
  739.      scoped" as in C.)
  740.  
  741.    For those familiar with Lisp, Emacs Lisp is modelled after MacLisp,
  742. an early dialect of Lisp developed at MIT (no relation to the Macintosh
  743. computer).  There is a Common Lisp compatibility package available for
  744. Emacs that provides many of the features of Common Lisp.
  745.  
  746.    The Java language is derived in many ways from C, and shares a
  747. similar syntax, but has the following features in common with Lisp (and
  748. different from C):
  749.  
  750.   1. Java is a safe language, like Lisp.
  751.  
  752.   2. Java provides garbage collection, like Lisp.
  753.  
  754.   3. Java has built-in facilities for handling errors and exceptions,
  755.      like Lisp.
  756.  
  757.   4. Java has a type system that combines the best advantages of both
  758.      static and dynamic typing.  Objects (except very simple types) are
  759.      explicitly marked with their type, as in dynamic typing; but there
  760.      is a hierarchy of types and functions are declared to accept only
  761.      certain types, thus providing the increased compile-time
  762.      error-checking of static typing.
  763.  
  764. 
  765. File: internals.info,  Node: XEmacs From the Perspective of Building,  Next: XEmacs From the Inside,  Prev: The Lisp Language,  Up: Top
  766.  
  767. XEmacs From the Perspective of Building
  768. ***************************************
  769.  
  770.    The heart of XEmacs is the Lisp environment, which is written in C.
  771. This is contained in the `src/' subdirectory.  Underneath `src/' are
  772. two subdirectories of header files: `s/' (header files for particular
  773. operating systems) and `m/' (header files for particular machine
  774. types).  In practice the distinction between the two types of header
  775. files is blurred.  These header files define or undefine certain
  776. preprocessor constants and macros to indicate particular
  777. characteristics of the associated machine or operating system.  As part
  778. of the configure process, one `s/' file and one `m/' file is identified
  779. for the particular environment in which XEmacs is being built.
  780.  
  781.    XEmacs also contains a great deal of Lisp code.  This implements the
  782. operations that make XEmacs useful as an editor as well as just a Lisp
  783. environment, and also contains many add-on packages that allow XEmacs
  784. to browse directories, act as a mail and Usenet news reader, compile
  785. Lisp code, etc.  There is actually more Lisp code than C code
  786. associated with XEmacs, but much of the Lisp code is peripheral to the
  787. actual operation of the editor.  The Lisp code all lies in
  788. subdirectories underneath the `lisp/' directory.
  789.  
  790.    The `lwlib/' directory contains C code that implements a generalized
  791. interface onto different X widget toolkits and also implements some
  792. widgets of its own that behave like Motif widgets but are faster, free,
  793. and in some cases more powerful.  The code in this directory compiles
  794. into a library and is mostly independent from XEmacs.
  795.  
  796.    The `etc/' directory contains various data files associated with
  797. XEmacs.  Some of them are actually read by XEmacs at startup; others
  798. merely contain useful information of various sorts.
  799.  
  800.    The `lib-src/' directory contains C code for various auxiliary
  801. programs that are used in connection with XEmacs.  Some of them are used
  802. during the build process; others are used to perform certain functions
  803. that cannot conveniently be placed in the XEmacs executable (e.g. the
  804. `movemail' program for fetching mail out of `/var/spool/mail', which
  805. must be setgid to `mail' on many systems; and the `gnuclient' program,
  806. which allows an external script to communicate with a running XEmacs
  807. process).
  808.  
  809.    The `man/' directory contains the sources for the XEmacs
  810. documentation.  It is mostly in a form called Texinfo, which can be
  811. converted into either a printed document (by passing it through TeX) or
  812. into on-line documentation called "info files".
  813.  
  814.    The `info/' directory contains the results of formatting the XEmacs
  815. documentation as "info files", for on-line use.  These files are used
  816. when you enter the Info system using `C-h i' or through the Help menu.
  817.  
  818.    The `dynodump/' directory contains auxiliary code used to build
  819. XEmacs on Solaris platforms.
  820.  
  821.    The other directories contain various miscellaneous code and
  822. information that is not normally used or needed.
  823.  
  824.    The first step of building involves running the `configure' program
  825. and passing it various parameters to specify any optional features you
  826. want and compiler arguments and such, as described in the `INSTALL'
  827. file.  This determines what the build environment is, chooses the
  828. appropriate `s/' and `m/' file, and runs a series of tests to determine
  829. many details about your environment, such as which library functions
  830. are available and exactly how they work. (The `s/' and `m/' files only
  831. contain information that cannot be conveniently detected in this
  832. fashion.) The reason for running these tests is that it allows XEmacs
  833. to be compiled on a much wider variety of platforms than those that the
  834. XEmacs developers happen to be familiar with, including various sorts
  835. of hybrid platforms.  This is especially important now that many
  836. operating systems give you a great deal of control over exactly what
  837. features you want installed, and allow for easy upgrading of parts of a
  838. system without upgrading the rest.  It would be impossible to
  839. pre-determine and pre-specify the information for all possible
  840. configurations.
  841.  
  842.    When configure is done running, it generates `Makefile's and the
  843. file `config.h' (which describes the features of your system) from
  844. template files.  You then run `make', which compiles the auxiliary code
  845. and programs in `lib-src/' and `lwlib/' and the main XEmacs executable
  846. in `src/'.  The result of this is an executable called `temacs', which
  847. is *not* the XEmacs executable.  `temacs' by itself cannot function as
  848. an editor or even display any windows on the screen, and if you simply
  849. run it, it will exit immediately.  The Makefile runs `temacs' with
  850. certain options that cause it to initialize itself, read in a number of
  851. basic Lisp files, and then dump itself out into a new executable called
  852. `xemacs'.  This new executable has been pre-initialized and contains
  853. pre-digested Lisp code that is necessary for the editor to function
  854. (this includes most basic Lisp functions, e.g. `not', that can be
  855. defined in terms of other Lisp primitives; some initialization code
  856. that is called when certain objects, such as frames, are created; and
  857. all of the standard keybindings and code for the actions they result
  858. in).  This executable, `xemacs', is the executable that you run to use
  859. the XEmacs editor.
  860.  
  861. 
  862. File: internals.info,  Node: XEmacs From the Inside,  Next: The XEmacs Object System (Abstractly Speaking),  Prev: XEmacs From the Perspective of Building,  Up: Top
  863.  
  864. XEmacs From the Inside
  865. **********************
  866.  
  867.    Internally, XEmacs is quite complex, and can be very confusing.  To
  868. simplify things, it can be useful to think of XEmacs as containing an
  869. event loop that "drives" everything, and a number of other subsystems,
  870. such as a Lisp engine and a redisplay mechanism.  Each of these other
  871. subsystems exists simultaneously in XEmacs, and each has a certain
  872. state.  The flow of control continually passes in and out of these
  873. different subsystems in the course of normal operation of the editor.
  874.  
  875.    It is important to keep in mind that, most of the time, the editor is
  876. "driven" by the event loop.  Except during initialization and batch
  877. mode, all subsystems are entered directly or indirectly through the
  878. event loop, and ultimately, control exits out of all subsystems back up
  879. to the event loop.  This cycle of entering a subsystem, exiting back out
  880. to the event loop, and starting another iteration of the event loop
  881. occurs once each keystroke, mouse motion, etc.
  882.  
  883.    If you're trying to understand a particular subsystem (other than the
  884. event loop), think of it as a "daemon" process or "servant" that is
  885. responsible for one particular aspect of a larger system, and
  886. periodically receives commands or environment changes that cause it to
  887. do something.  Ultimately, these commands and environment changes are
  888. always triggered by the event loop.  For example:
  889.  
  890.    * The window and frame mechanism is responsible for keeping track of
  891.      what windows and frames exist, what buffers are in them, etc.  It
  892.      is periodically given commands (usually from the user) to make a
  893.      change to the current window/frame state: i.e. create a new frame,
  894.      delete a window, etc.
  895.  
  896.    * The buffer mechanism is responsible for keeping track of what
  897.      buffers exist and what text is in them.  It is periodically given
  898.      commands (usually from the user) to insert or delete text, create
  899.      a buffer, etc.  When it receives a text-change command, it
  900.      notifies the redisplay mechanism.
  901.  
  902.    * The redisplay mechanism is responsible for making sure that
  903.      windows and frames are displayed correctly.  It is periodically
  904.      told (by the event loop) to actually "do its job", i.e. snoop
  905.      around and see what the current state of the environment (mostly
  906.      of the currently-existing windows, frames, and buffers) is, and
  907.      make sure that that state matches what's actually displayed.  It
  908.      keeps lots and lots of information around (such as what is
  909.      actually being displayed currently, and what the environment was
  910.      last time it checked) so that it can minimize the work it has to
  911.      do.  It is also helped along in that whenever a relevant change to
  912.      the environment occurs, the redisplay mechanism is told about
  913.      this, so it has a pretty good idea of where it has to look to find
  914.      possible changes and doesn't have to look everywhere.
  915.  
  916.    * The Lisp engine is responsible for executing the Lisp code in
  917.      which most user commands are written.  It is entered through a
  918.      call to `eval' or `funcall', which occurs as a result of
  919.      dispatching an event from the event loop.  The functions it calls
  920.      issue commands to the buffer mechanism, the window/frame
  921.      subsystem, etc.
  922.  
  923.    * The Lisp allocation subsystem is responsible for keeping track of
  924.      Lisp objects.  It is given commands from the Lisp engine to
  925.      allocate objects, garbage collect, etc.
  926.  
  927.    etc.
  928.  
  929.    The important idea here is that there are a number of independent
  930. subsystems each with its own responsibility and persistent state, just
  931. like different employees in a company, and each subsystem is
  932. periodically given commands from other subsystems.  Commands can flow
  933. from any one subsystem to any other, but there is usually some sort of
  934. hierarchy, with all commands originating from the event subsystem.
  935.  
  936.    XEmacs is entered in `main()', which is in `emacs.c'.  When this is
  937. called the first time (in a properly-invoked `temacs'), it does the
  938. following:
  939.  
  940.   1. It does some very basic environment initializations, such as
  941.      determining where it and its directories (e.g. `lisp/' and `etc/')
  942.      reside and setting up signal handlers.
  943.  
  944.   2. It initializes the entire Lisp interpreter.
  945.  
  946.   3. It sets the initial values of many built-in variables (including
  947.      many variables that are visible to Lisp programs), such as the
  948.      global keymap object and the built-in faces (a face is an object
  949.      that describes the display characteristics of text).  This
  950.      involves creating Lisp objects and thus is dependent on step (2).
  951.  
  952.   4. It performs various other initializations that are relevant to the
  953.      particular environment it is running in, such as retrieving
  954.      environment variables, determining the current date and the user
  955.      who is running the program, examining its standard input, creating
  956.      any necessary file descriptors, etc.
  957.  
  958.   5. At this point, the C initialization is complete.  A Lisp program
  959.      that was specified on the command line (usually `loadup.el') is
  960.      called (temacs is normally invoked as `temacs -batch -l loadup.el
  961.      dump').  `loadup.el' loads all of the other Lisp files that are
  962.      needed for the operation of the editor, calls the `dump-emacs'
  963.      function to write out `xemacs', and then kills the temacs process.
  964.  
  965.    When `xemacs' is then run, it only redoes steps (1) and (4) above;
  966. all variables already contain the values they were set to when the
  967. executable was dumped, and all memory that was allocated with
  968. `malloc()' is still around. (XEmacs knows whether it is being run as
  969. `xemacs' or `temacs' because it sets the global variable `initialized'
  970. to 1 after step (4) above.) At this point, `xemacs' calls a Lisp
  971. function to do any further initialization, which includes parsing the
  972. command-line (the C code can only do limited command-line parsing,
  973. which includes looking for the `-batch' and `-l' flags and a few other
  974. flags that it needs to know about before initialization is complete),
  975. creating the first frame (or "window" in standard window-system
  976. parlance), running the user's init file (usually the file `.emacs' in
  977. the user's home directory), etc.  The function to do this is usually
  978. called `normal-top-level'; `loadup.el' tells the C code about this
  979. function by setting its name as the value of the Lisp variable
  980. `top-level'.
  981.  
  982.    When the Lisp initialization code is done, the C code enters the
  983. event loop, and stays there for the duration of the XEmacs process.
  984. The code for the event loop is contained in `keyboard.c', and is called
  985. `Fcommand_loop_1()'.  Note that this event loop could very well be
  986. written in Lisp, and in fact a Lisp version exists; but apparently,
  987. doing this makes XEmacs run noticeably slower.
  988.  
  989.    Notice how much of the initialization is done in Lisp, not in C.  In
  990. general, XEmacs tries to move as much code as is possible into Lisp.
  991. Code that remains in C is code that implements the Lisp interpreter
  992. itself, or code that needs to be very fast, or code that needs to do
  993. system calls or other such stuff that needs to be done in C, or code
  994. that needs to have access to "forbidden" structures. (One conscious
  995. aspect of the design of Lisp under XEmacs is a clean separation between
  996. the external interface to a Lisp object's functionality and its internal
  997. implementation.  Part of this design is that Lisp programs are
  998. forbidden from accessing the contents of the object other than through
  999. using a standard API.  In this respect, XEmacs Lisp is similar to
  1000. modern Lisp dialects but differs from GNU Emacs, which tends to expose
  1001. the implementation and allow Lisp programs to look at it directly.  The
  1002. major advantage of hiding the implementation is that it allows the
  1003. implementation to be redesigned without affecting any Lisp programs,
  1004. including those that might want to be "clever" by looking directly at
  1005. the object's contents and possibly manipulating them.)
  1006.  
  1007.    Moving code into Lisp makes the code easier to debug and maintain and
  1008. makes it much easier for people who are not XEmacs developers to
  1009. customize XEmacs, because they can make a change with much less chance
  1010. of obscure and unwanted interactions occurring than if they were to
  1011. change the C code.
  1012.  
  1013.